package MyGame;

import DEMOS.LayerTwo;
import edu.chalmers.AV_2DPlatformerFramework.Model.AnimatedTexture;
import edu.chalmers.AV_2DPlatformerFramework.Model.GameObject;
import edu.chalmers.AV_2DPlatformerFramework.Model.Hitbox;
import edu.chalmers.AV_2DPlatformerFramework.Model.NoninteractionLayer;
import edu.chalmers.AV_2DPlatformerFramework.Model.Texture;
import edu.chalmers.AV_2DPlatformerFramework.Utility.Vector2D;

/**
 * @version 0.1
 * @author Andrea Buchholz
 */
public class Object_Edmund extends GameObject{

    public Object_Edmund() throws Hitbox.HitboxMalformedException {
        super(null);

        Vector2D[] vertices = {new Vector2D(0, 0), new Vector2D(80, 0), 
            new Vector2D(80, 100), new Vector2D(0, 100)};
        
        this.setStrata(1000);
        this.setHitbox(new Hitbox(vertices));
        String s = System.getProperty("file.separator");
        this.addTexture(
                new Texture("."+s+"src"+s+"main"+s+"java"+s+"Textures"
                            +s+"EdmundRight.png", this.getHitbox().getBounds2D()));
        
                this.addTexture(
                    new Texture("."+s+"src"+s+"main"+s+"java"+s+"Textures"
                        +s+"EdmundLeft.png", this.getHitbox().getBounds2D()));
    }
    
    @Override
    public void onCollision(GameObject otherObject) {
        if (otherObject instanceof Object_MathDude){
            //Set in new front-layer
            this.setLayer(new NoninteractionLayer());
            AnimatedTexture at = (AnimatedTexture) otherObject.getCurrentTexture();
            at.setScreenTime(1);
            this.setVelocity(new Vector2D(-1, -2));
            System.out.println("Ooops! You died!");
        }
        else if (otherObject instanceof Object_CanisterShot){
            //Set in new front-layer
            otherObject.setLayer(new NoninteractionLayer());
            otherObject.setPosition(new Vector2D(100000, 0));
            System.out.println("Ooops! You died!");
        }
    }

    @Override
    public GameObject copy() {
        try {
           Object_Edmund copy = new Object_Edmund();
           this.copyVariablesTo(copy);
           return copy;
        } catch (Hitbox.HitboxMalformedException ex) {
            return null;
        }
    }
}